<?
$_GET['chpu'] = eregi_replace('/$','',$_GET['chpu']);
$_GET['chpu'] = eregi_replace('.htm$','',$_GET['chpu']);
$_GET['chpu'] = eregi_replace('.html$','',$_GET['chpu']);

$bd->QueryObj('
				SELECT
						url,
						chpu
					FROM
						' . WWW_TABLE_PREFIX . 'chpu_url
					WHERE
						"' . $_GET['chpu'] . '" LIKE REPLACE(chpu, "*", "%")
					ORDER BY
						sort
			');
if ($bd->data->url)
{
	$url_part = Array();
	$regexp = eregi_replace('\*', '(.*?)', $bd->data->chpu);
	preg_match('#^' . $regexp . '$#', $_GET['chpu'], $CHPU);

	$url = explode('*', $bd->data->url);
	$count = count($CHPU) + count($url) - 1;
		
				$url_i = 0;
				$url_part_i = 1;
				for ($i = 0; $i < $count; $i++)
				{
					if (!($i % 2))
					{
						$add = $url[$url_i];
						$url_i++;
					}
					else
					{
						$add = $CHPU[$url_part_i];
						$url_part_i++;
					}
					$url2 .= $add;
				}

				$CHPU = explode('/',$url2);
				$plugin = array_shift($CHPU);
				

	
	//$query = array_shift($CHPU);

	$sql = 'SELECT * FROM ' . WWW_TABLE_PREFIX . 'plugins WHERE plugin="' . $plugin .'"';
	
	$bd->QueryObj($sql);

	if ($bd->data)
	{
		require_once($__ROOT_PATH . $bd->data->file);
		if ($status != true)
		{
			require_once($__ROOT_PATH . '404error.php');
			exit;
		}
		//Starting autostart

		$autorun_plugins = new SQL;

		$sql = 'SELECT * FROM ' . WWW_TABLE_PREFIX . 'autostart';
		for($autorun_plugins->QueryObj($sql);$autorun_plugins->data;$autorun_plugins->NextObj())
		{
			require_once($__ROOT_PATH . $autorun_plugins->data->file);
		}
		
		
		if (sizeof($lastModifiedArray))
		{
			rsort($lastModifiedArray);
			$lastModified =  strtotime($lastModifiedArray[0]);
		}
		else
		{
			$lastModified = time();
		}

		//Thu, 19 Oct 2000 10:05:38 GMT

		header("Pragma: public");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		header('Last-Modified: ' . gmstrftime('%a, %e %b %Y %R GMT',$lastModified));
	


		$TEMPLATE->pparse('body');
		exit;

	}
	else
	{
		require_once($__ROOT_PATH . '404error.php');
		exit;
	}

}
else
{
	require_once($__ROOT_PATH . '404error.php');
	exit;
}


?>